package com.approval.approvalapp.center.acitivty;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.approval.approvalapp.R;
import com.approval.approvalapp.bean.HyxqBean;
import com.approval.approvalapp.center.centerfragment.HyspDbFragment;
import com.approval.approvalapp.center.centerfragment.HyspYbFragment;
import com.approval.approvalapp.index.dbsx.tshf.BaseActivity2;
import com.approval.approvalapp.util.ErrorBeanUtil;
import com.approval.approvalapp.util.base.BaseActivity;
import com.approval.approvalapp.util.net.NetRequsetUtil;
import com.approval.approvalapp.util.net.interfacepac.NetDownResponse;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

public class HyspXqActivity extends BaseActivity2 {

    @Bind(R.id.back_iv)
    ImageView backIv;
    @Bind(R.id.titleTv1)
    TextView titleTv1;
    @Bind(R.id.name_tv)
    TextView nameTv;
    @Bind(R.id.hyzt_tv)
    TextView hyztTv;
    @Bind(R.id.kssj_tv)
    TextView kssjTv;
    @Bind(R.id.jssj_tv)
    TextView jssjTv;
    @Bind(R.id.khsx_tv)
    TextView khsxTv;
    @Bind(R.id.sfxyty_tv)
    TextView sfxytyTv;
    @Bind(R.id.chrs_tv)
    TextView chrsTv;
    @Bind(R.id.lxdh_tv)
    TextView lxdhTv;
    @Bind(R.id.hynr_tv)
    TextView hynrTv;
    @Bind(R.id.bz_tv)
    TextView bzTv;
    @Bind(R.id.refuse_tv)
    LinearLayout refuseTv;
    @Bind(R.id.agree_tv)
    LinearLayout agreeTv;
    @Bind(R.id.bottom_ll)
    LinearLayout bottom_ll;
    @Bind(R.id.colorIv)
    CircleImageView colorIv;
    @Bind(R.id.colorTv)
    TextView colorTv;
    private int id;
    @Bind(R.id.bz_ll)
    LinearLayout bz_ll;
    @Bind(R.id.hystv)
    TextView hystv;

    @Override
    public int getLayoutId() {
        return R.layout.activity_hysp_xq;
    }

    @Override
    public void initView() {
        String name = getIntent().getStringExtra("name");
        String imTitle = getIntent().getStringExtra("ImTitle");
        String imStartTime = getIntent().getStringExtra("ImStartTime");
        String imEndTime = getIntent().getStringExtra("ImEndTime");
        String isUserNo = getIntent().getStringExtra("ImUserNo");
        String tel = getIntent().getStringExtra("tel");
        id = getIntent().getIntExtra("id" , 0);
        int ImStart = getIntent().getIntExtra("ImStart", 0);
        hystv.setText("会议室申请-" + getIntent().getStringExtra("place"));
        //0 待审核 1 通过 2 不通过
        if (ImStart == 0) {
            bottom_ll.setVisibility(View.VISIBLE);
            ColorDrawable colorDrawable = new ColorDrawable(
                    getResources().getColor(R.color.yellow));
            colorIv.setImageDrawable(colorDrawable);
            colorTv.setText("审核中");
            colorTv.setTextColor(Color.parseColor("#FFF8AF35"));

        } else if (ImStart == 1){
            bottom_ll.setVisibility(View.GONE);
            ColorDrawable colorDrawable = new ColorDrawable(
                    getResources().getColor(R.color.colorAccent));

            colorIv.setImageDrawable(colorDrawable);
            colorTv.setText("审核通过");
            colorTv.setTextColor(Color.parseColor("#1465FD"));
        }else {
            bottom_ll.setVisibility(View.GONE);
            ColorDrawable colorDrawable = new ColorDrawable(
                    getResources().getColor(R.color.red));
            colorIv.setImageDrawable(colorDrawable);
            colorTv.setText("审核不通过");
            colorTv.setTextColor(Color.parseColor("#DE463A"));
        }
        titleTv1.setText(name + "的会议室使用申请");
        nameTv.setText(name);
        hyztTv.setText(imTitle);
        kssjTv.setText(imStartTime);
        jssjTv.setText(imEndTime);
        chrsTv.setText(isUserNo);
        lxdhTv.setText(tel);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id",id);
        NetRequsetUtil.getInstance().netRequestPostJson("v1/center/meeting_show",
                jsonObject.toString(), new NetDownResponse() {
            @Override
            public void success(String str) {
                Log.d("sss", str);
                List<HyxqBean> hyxqBeans = JSON.parseArray(str, HyxqBean.class);
                HyxqBean hyxqBean = hyxqBeans.get(0);

                if (khsxTv == null){
                    return;
                }

                khsxTv.setText(hyxqBean.getFdsxmc());
                if (hyxqBean.getImFunctionName() != null){
                    hynrTv.setText(hyxqBean.getImFunctionName());
                }

                if (hyxqBean.getIFTY().equals("0")){
                    sfxytyTv.setText("不需要");
                }else {
                    sfxytyTv.setText("需要");
                }

                if (hyxqBean.getHYBZ() == null || TextUtils.isEmpty(hyxqBean.getHYBZ())){
                    bz_ll.setVisibility(View.GONE);
                }
                bzTv.setText(hyxqBean.getHYBZ());

            }

            @Override
            public void errowithresponse(String str) {
                ErrorBeanUtil.getErrorMessage(str);
            }

            @Override
            public void erro() {

            }

            @Override
            public void finish() {

            }
        });

    }

    @Override
    public void initData() {

    }

    @OnClick({R.id.back_iv, R.id.refuse_tv, R.id.agree_tv})
    public void onViewClicked(View view) {
        JSONObject jsonObject = new JSONObject();
        switch (view.getId()) {
            case R.id.back_iv:
                finish();
                break;
            case R.id.refuse_tv:
                jsonObject.put("meeting_id",id);
                jsonObject.put("type","2");
                NetRequsetUtil.getInstance().netRequestPostJson(
                                "v1/center/meeting_yes_no",
                        jsonObject.toString(),
                        new NetDownResponse() {
                            @Override
                            public void success(String str) {
                                Toast.makeText(HyspXqActivity.this, "处理完成", Toast.LENGTH_SHORT).show();
                                HyspXqActivity.this.finish();
                                if (HyspDbFragment.instance != null){
                                    HyspDbFragment.instance.refreshData();
                                }
                                if (HyspYbFragment.instance != null){
                                    HyspYbFragment.instance.refreshData();
                                }
                            }

                            @Override
                            public void errowithresponse(String str) {
                                ErrorBeanUtil.getErrorMessage(str);
                            }

                            @Override
                            public void erro() {

                            }

                            @Override
                            public void finish() {

                            }
                        });
                break;
            case R.id.agree_tv:
                jsonObject.put("meeting_id",id);
                jsonObject.put("type","1");
                NetRequsetUtil.getInstance().netRequestPostJson(
                        "v1/center/meeting_yes_no",
                        jsonObject.toString(),
                        new NetDownResponse() {
                            @Override
                            public void success(String str) {
                                Toast.makeText(HyspXqActivity.this, "处理完成", Toast.LENGTH_SHORT).show();
                                HyspXqActivity.this.finish();
                                if (HyspDbFragment.instance != null){
                                    HyspDbFragment.instance.refreshData();
                                }
                                if (HyspYbFragment.instance != null){
                                    HyspYbFragment.instance.refreshData();
                                }
                            }

                            @Override
                            public void errowithresponse(String str) {
                                ErrorBeanUtil.getErrorMessage(str);
                            }

                            @Override
                            public void erro() {

                            }

                            @Override
                            public void finish() {

                            }
                        });
                break;
        }
    }


}
